import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.getItem('token') || '', // 前面有值用前面的, 前面要是null, 就用后面的
    refresh_token: localStorage.getItem('refresh_token') || ''
  },
  mutations: {
    setToken (state, token) {
      state.token = token // 把请求成功后返回的token赋予state.token
      localStorage.setItem('token', token) // 把token存储到本地
    },
    setRefreshToken (state, refreshToken) {
      state.refresh_token = refreshToken
      localStorage.setItem('refresh_token', refreshToken)
    }
  },

  actions: {
  },
  modules: {
  }
})
